﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.LongER.Framework.Utils;
using Com.LongER.UI;
using Com.LongER.Business.ZHM010;
using Com.LongER.Framework.Utils.LogUtils;

public partial class ZHM010 : ABasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //
        if (!this.Page.IsPostBack)
        {
        Label lblPageId = (Label)Master.FindControl("lblPageId");
        lblPageId.Text = "ZHM010";

        Label lblPageName = (Label)Master.FindControl("lblPageName");
        lblPageName.Text = "客户详细管理画面";
            //清空画面中的输入框
            #region
            proc清空_Init("0");
            #endregion
        }
    }
    protected void btn主菜单_Click(object sender, EventArgs e)
    {
        Response.Redirect("/LongER/ZAH003.aspx");
    }
	
    protected void btn执行_Click(object sender, EventArgs e)
    {
        //初期化处理
        #region
        //错误信息
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsgCD.Text = "";
        lblMsg.Text = "";

        #endregion

        //处理区分进行确认
        if (this.txt处理区分.Text == string.Empty) //处理区分为空的场合
        {
            this.SetMessage("GTH000", "IGTH000001", MSG_LEVEL.Info);
            this.AddCssClass(this.txt处理区分, CSS_TEXT_ERROR);
            return;
        }
        else if (this.txt处理区分.Text == "1") //处理区分为1(查询)的场合
        {
            #region
            //txt客户CD为空时
            if (this.txt客户CD.Text == string.Empty)
            {
                this.SetMessage("GTH002", "IGTH002002", MSG_LEVEL.Error);
                this.AddCssClass(this.txt客户CD, CSS_TEXT_ERROR);
                return;
            }

            //通过txt客户CD进行查询
            
            CZHM010 instance = new CZHM010();
            ZHM010DS.M_KEHUDETAILDataTable dt = instance.GetMKehuDetail(this.txt客户CD.Text);
            if (dt.Count <= 0)
            {
                //查询失败
                this.SetMessage("GTH002", "IGTH002001", MSG_LEVEL.Error);
                this.AddCssClass(this.txt客户CD, CSS_TEXT_ERROR);
                this.txt客户CD.Focus();
                return;
            }
            else
            {
                this.SetMessage("GTH002", "IGTH002000", MSG_LEVEL.Info);
                this.txt客户名.Text = dt[0].KEHU_HANZI.ToString();
                this.txt联系人.Text = dt[0].LIANXI_REN.ToString();
                this.txt证件种别CD.Text = dt[0].ZHENGJIAN_ZB.ToString();
                this.txt证件种别.Text = dt[0].ZJZB_HANZI.ToString();
                this.txt证件号码.Text = dt[0].ZHENGJIAN_NUM.ToString();
                this.txt联系电话1.Text = dt[0].TEL_NUM1.ToString();
                this.txt联系电话2.Text = dt[0].TEL_NUM1.ToString();
                this.txt传真号1.Text = dt[0].FAX1.ToString();
                this.txt传真号2.Text = dt[0].FAX2.ToString();
                this.txt邮箱.Text = dt[0].MAIL_ADDR.ToString();

                this.txt详细地址.Text = dt[0].GONGSI_ADDR.ToString();
                this.txt邮政编码.Text = dt[0].POST.ToString();
                this.txt所属区分CD.Text = dt[0].SHO.ToString();
                this.txt所属区分.Text = dt[0].SSQF_HANZI.ToString();
                this.txt合作性质CD.Text = dt[0].HEZUO_XINGZHI.ToString();
                this.txt合作性质.Text = dt[0].HZXZ_HANZI.ToString();
                this.txt公司性质CD.Text = dt[0].GONGSI_XINGZHI.ToString();
                this.txt公司性质.Text = dt[0].GSXZ_HANZI.ToString();
                this.txt银行账号名1.Text = dt[0].YINHANG1.ToString();
                this.txt银行卡种别1CD.Text = dt[0].YH_CARD_ZB1.ToString();
                this.txt银行卡种别1.Text = dt[0].YHZB1_HANZI.ToString();
                this.txt银行账号1.Text = dt[0].YH_CARD_NUM1.ToString();
                this.txt银行账号名2.Text = dt[0].YINHANG2.ToString();
                this.txt银行卡种别2CD.Text = dt[0].YH_CARD_ZB2.ToString();
                this.txt银行卡种别2.Text = dt[0].YHZB2_HANZI.ToString();
                this.txt银行账号2.Text = dt[0].YH_CARD_NUM2.ToString();
                this.txt银行账号名3.Text = dt[0].YINHANG3.ToString();
                this.txt银行卡种别3CD.Text = dt[0].YH_CARD_ZB3.ToString();
                this.txt银行卡种别3.Text = dt[0].YHZB3_HANZI.ToString();
                this.txt银行账号3.Text = dt[0].YH_CARD_NUM3.ToString();

                this.txt支付方式CD.Text = dt[0].ZHIFU_FANGSHI.ToString();
                this.txt支付方式.Text = dt[0].ZFFS_HANZI.ToString();
                this.txt备注.Text = dt[0].BEIZHU.ToString();
                this.txt客户CD.Focus();
            }
            #endregion

        }
        else if (this.txt处理区分.Text == "2") //处理区分为2(登记)的场合
        {
            #region
            //客户CD的值进行检查
            #region
            if (this.txt客户CD.Text.Trim() == string.Empty)
            {
                //客户CD为空的场合,退出登陆
                this.SetMessage("ZHM010", "IZHM010000", MSG_LEVEL.Error);
                this.AddCssClass(this.txt客户CD, CSS_TEXT_ERROR);
                return;
            }
            else {
                //对客户CD进行查询
                CZHM010 instanceSelectMKehu = new CZHM010();
                ZHM010DS.M_KEHUDETAILDataTable dtSelectMKehu = instanceSelectMKehu.GetMKehuDetail(this.txt客户CD.Text);
                if (dtSelectMKehu.Count > 0)
                {
                    //客户CD已存在场合,退出登陆
                    this.SetMessage("ZHM010", "IZHM010001", MSG_LEVEL.Error);
                    this.AddCssClass(this.txt客户CD, CSS_TEXT_ERROR);
                    this.txt客户CD.Focus();
                    return;
                }
            }
            #endregion

            //执行登记
            #region
            Boolean isInserted = false;
            CZHM010 instance = new CZHM010();
            isInserted = instance.InsertMKehu(this.txt客户CD.Text, this.txt客户名.Text, this.txt所属区分CD.Text , 
                                                this.txt合作性质CD.Text, this.txt详细地址.Text , this.txt邮政编码.Text,
                                                this.txt公司性质CD.Text, this.txt联系人.Text , 
                                                this.txt证件种别CD.Text, this.txt联系电话1.Text , this.txt证件号码.Text, 
                                                this.txt联系电话2.Text , 
                                                this.txt传真号1.Text, this.txt传真号2.Text , 
                                                this.txt邮箱.Text, 
                                                this.txt银行账号名1.Text , this.txt银行卡种别1.Text, this.txt银行账号1.Text , 
                                                this.txt银行账号名2.Text , this.txt银行卡种别2.Text, this.txt银行账号2.Text , 
                                                this.txt银行账号名3.Text , this.txt银行卡种别3.Text, this.txt银行账号3.Text , 
                                                this.txt支付方式CD.Text, this.txt备注.Text
                                                 );
            if (!isInserted)
            {
                this.SetMessage("GTH003", "IGTH003002", MSG_LEVEL.Error);
                this.AddCssClass(this.txt客户CD, CSS_TEXT_ERROR);
                this.txt客户CD.Focus();
            }
            else
            {
                this.SetMessage("GTH003", "IGTH003000", MSG_LEVEL.Info);
                this.AddCssClass(this.txt客户CD, CSS_TEXT_ERROR);
                this.txt客户CD.Focus();
            }
            #endregion

            #endregion
        }
        else if (this.txt处理区分.Text == "3") //处理区分为1(订正)的场合
        {
            #region
            //执行更新
            Boolean isChanged = false;
            CZHM010 instance = new CZHM010();
            isChanged = instance.UpdateMKehu(this.txt客户名.Text,this.txt所属区分CD.Text
                                                 , this.txt公司性质CD.Text, this.txt详细地址.Text
                                                 , this.txt邮政编码.Text, this.txt公司性质CD.Text
                                                 , this.txt联系人.Text, this.txt证件种别CD.Text, this.txt证件号码.Text
                                                 , this.txt联系电话1.Text, this.txt联系电话2.Text
                                                 , this.txt传真号1.Text, this.txt传真号2.Text
                                                 , this.txt邮箱.Text
                                                 , this.txt银行账号名1.Text, this.txt银行卡种别1.Text, this.txt银行账号1.Text
                                                 , this.txt银行账号名2.Text, this.txt银行卡种别2.Text, this.txt银行账号2.Text
                                                 , this.txt银行账号名3.Text, this.txt银行卡种别2.Text, this.txt银行账号3.Text
                                                 , this.txt支付方式CD.Text
                                                 , this.txt客户CD.Text
                                                 );
            if (!isChanged)
            {
                //更新失败
                String msg = MessageUtil.GetMessage("GTH001", "IGTH001002");
                lblMsgCD.Text = "IGTH001002";
                lblMsg.Text = msg;
                this.txt客户CD.Focus();
            }
            else
            {
                //更新成功
                String msg = MessageUtil.GetMessage("GTH001", "IGTH001000");
                lblMsgCD.Text = "IGTH001000";
                lblMsg.Text = msg;
                this.txt客户CD.Focus();
            }
            #endregion

        }
        else if (this.txt处理区分.Text == "9") //处理区分为1(删除)的场合
        {
            #region
            //执行删除
            Boolean isDeleted = false;
            CZHM010 instance = new CZHM010();
            isDeleted = instance.DeleteMKehu(this.txt客户CD.Text);
            if (!isDeleted)
            {
                //删除失败
                String msg = MessageUtil.GetMessage("GTH004", "IGTH004002");
                lblMsgCD.Text = "IGTH004002";
                lblMsg.Text = msg;
                this.txt客户CD.Focus();
            }
            else
            {
                //删除成功
                String msg = MessageUtil.GetMessage("GTH004", "IGTH004000");
                lblMsgCD.Text = "IGTH004000";
                lblMsg.Text = msg;
                this.txt客户CD.Focus();
            }

            #endregion
        }
        else //处理区分为上述以外的场合
        {
            String msg = MessageUtil.GetMessage("GTH000", "IGTH000002");
            lblMsgCD.Text = "IGTH000002";
            lblMsg.Text = msg;
            return;
        }

    }

    protected void proc清空_Init(string str处理区分)
    {
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsgCD.Text = "";
        lblMsg.Text = "";
        //this.SetMessage("", "", MSG_LEVEL.Info);

        //初期化
        if (str处理区分 == "0")
        {
            //控件的Enabled进行控制
            #region
            this.txt客户CD.Enabled = true;

            this.txt客户名.Enabled = false;
            this.txt联系人.Enabled = false;
            this.txt证件种别CD.Enabled = false;
            this.txt证件号码.Enabled = false;
            this.txt联系电话1.Enabled = false;
            this.txt传真号1.Enabled = false;
            this.txt传真号2.Enabled = false;
            this.txt邮箱.Enabled = false;

            this.txt详细地址.Enabled = false;
            this.txt邮政编码.Enabled = false;
            this.txt所属区分CD.Enabled = false;
            this.txt合作性质CD.Enabled = false;
            this.txt公司性质CD.Enabled = false;
            this.txt银行账号名1.Enabled = false;
            this.txt银行卡种别1.Enabled = false;
            this.txt银行账号1.Enabled = false;
            this.txt银行账号名2.Enabled = false;
            this.txt银行卡种别2.Enabled = false;
            this.txt银行账号2.Enabled = false;
            this.txt银行账号名3.Enabled = false;
            this.txt银行卡种别3.Enabled = false;
            this.txt银行账号3.Enabled = false;

            this.txt支付方式CD.Enabled = false;
            this.txt备注.Enabled = false;
            #endregion

            //控件的Text进行清空
            #region
            this.txt处理区分.Text = string.Empty;
            this.txt处理区分.Focus();

            this.txt客户CD.Text = string.Empty;
            this.txt客户名.Text = string.Empty;
            this.txt联系人.Text = string.Empty;
            this.txt证件种别CD.Text = string.Empty;
            this.txt证件号码.Text = string.Empty;
            this.txt联系电话1.Text = string.Empty;
            this.txt联系电话2.Text = string.Empty;
            this.txt传真号1.Text = string.Empty;
            this.txt传真号2.Text = string.Empty;
            this.txt邮箱.Text = string.Empty;

            this.txt详细地址.Text = string.Empty;
            this.txt邮政编码.Text = string.Empty;
            this.txt所属区分CD.Text = string.Empty;
            this.txt合作性质CD.Text = string.Empty;
            this.txt公司性质CD.Text = string.Empty;
            this.txt银行账号名1.Text = string.Empty;
            this.txt银行卡种别1CD.Text = string.Empty;
            this.txt银行卡种别1.Text = string.Empty;
            this.txt银行账号1.Text = string.Empty;
            this.txt银行账号名2.Text = string.Empty;
            this.txt银行卡种别2CD.Text = string.Empty;
            this.txt银行卡种别2.Text = string.Empty;
            this.txt银行账号2.Text = string.Empty;
            this.txt银行账号名3.Text = string.Empty;
            this.txt银行卡种别3CD.Text = string.Empty;
            this.txt银行卡种别3.Text = string.Empty;
            this.txt银行账号3.Text = string.Empty;

            this.txt支付方式CD.Text = string.Empty;
            this.txt备注.Text = string.Empty;

            #endregion
        }
        
        //查询
        if (str处理区分 == "1" )
        {
            //控件的Enabled进行控制
            #region
            this.txt客户CD.Enabled = true;

            this.txt客户名.Enabled = false;
            this.txt联系人.Enabled = false;
            this.txt证件种别CD.Enabled = false;
            this.txt证件号码.Enabled = false;
            this.txt联系电话1.Enabled = false;
            this.txt传真号1.Enabled = false;
            this.txt传真号2.Enabled = false;
            this.txt邮箱.Enabled = false;

            this.txt详细地址.Enabled = false;
            this.txt邮政编码.Enabled = false;
            this.txt所属区分CD.Enabled = false;
            this.txt合作性质CD.Enabled = false;
            this.txt公司性质CD.Enabled = false;
            this.txt银行账号名1.Enabled = false;
            this.txt银行卡种别1.Enabled = false;
            this.txt银行账号1.Enabled = false;
            this.txt银行账号名2.Enabled = false;
            this.txt银行卡种别2.Enabled = false;
            this.txt银行账号2.Enabled = false;
            this.txt银行账号名3.Enabled = false;
            this.txt银行卡种别3.Enabled = false;
            this.txt银行账号3.Enabled = false;

            this.txt支付方式CD.Enabled = false;
            this.txt备注.Enabled = false;
            #endregion

            //控件的Text进行清空
            #region
            this.txt客户CD.Focus();

            this.txt客户CD.Text = string.Empty;
            this.txt客户名.Text = string.Empty;
            this.txt联系人.Text = string.Empty;
            this.txt证件种别CD.Text = string.Empty;
            this.txt证件号码.Text = string.Empty;
            this.txt联系电话1.Text = string.Empty;
            this.txt联系电话2.Text = string.Empty;
            this.txt传真号1.Text = string.Empty;
            this.txt传真号2.Text = string.Empty;
            this.txt邮箱.Text = string.Empty;

            this.txt详细地址.Text = string.Empty;
            this.txt邮政编码.Text = string.Empty;
            this.txt所属区分CD.Text = string.Empty;
            this.txt合作性质CD.Text = string.Empty;
            this.txt公司性质CD.Text = string.Empty;
            this.txt银行账号名1.Text = string.Empty;
            this.txt银行卡种别1CD.Text = string.Empty;
            this.txt银行卡种别1.Text = string.Empty;
            this.txt银行账号1.Text = string.Empty;
            this.txt银行账号名2.Text = string.Empty;
            this.txt银行卡种别2CD.Text = string.Empty;
            this.txt银行卡种别2.Text = string.Empty;
            this.txt银行账号2.Text = string.Empty;
            this.txt银行账号名3.Text = string.Empty;
            this.txt银行卡种别3CD.Text = string.Empty;
            this.txt银行卡种别3.Text = string.Empty;
            this.txt银行账号3.Text = string.Empty;

            this.txt支付方式CD.Text = string.Empty;
            this.txt备注.Text = string.Empty;

            #endregion
        }

        //登记或订正
        if (str处理区分 == "2" || str处理区分 == "3")
        {
            //控件的Enabled进行控制
            #region
            this.txt客户CD.Enabled = true;

            this.txt客户名.Enabled = true;
            this.txt联系人.Enabled = true;
            this.txt证件种别CD.Enabled = true;
            this.txt证件号码.Enabled = true;
            this.txt联系电话1.Enabled = true;
            this.txt传真号1.Enabled = true;
            this.txt传真号2.Enabled = true;
            this.txt邮箱.Enabled = true;

            this.txt详细地址.Enabled = true;
            this.txt邮政编码.Enabled = true;
            this.txt所属区分CD.Enabled = true;
            this.txt合作性质CD.Enabled = true;
            this.txt公司性质CD.Enabled = true;
            this.txt银行账号名1.Enabled = true;
            this.txt银行卡种别1.Enabled = true;
            this.txt银行账号1.Enabled = true;
            this.txt银行账号名2.Enabled = true;
            this.txt银行卡种别2.Enabled = true;
            this.txt银行账号2.Enabled = true;
            this.txt银行账号名3.Enabled = true;
            this.txt银行卡种别3.Enabled = true;
            this.txt银行账号3.Enabled = true;

            this.txt支付方式CD.Enabled = true;
            this.txt备注.Enabled = true;
            #endregion

            //控件的Text进行清空
            #region
            #endregion
        }

        //删除
        if (str处理区分 == "9")
        {
            //控件的Enabled进行控制
            #region
            this.txt客户CD.Enabled = true;

            this.txt客户名.Enabled = false;
            this.txt联系人.Enabled = false;
            this.txt证件种别CD.Enabled = false;
            this.txt证件号码.Enabled = false;
            this.txt联系电话1.Enabled = false;
            this.txt传真号1.Enabled = false;
            this.txt传真号2.Enabled = false;
            this.txt邮箱.Enabled = false;

            this.txt详细地址.Enabled = false;
            this.txt邮政编码.Enabled = false;
            this.txt所属区分CD.Enabled = false;
            this.txt合作性质CD.Enabled = false;
            this.txt公司性质CD.Enabled = false;
            this.txt银行账号名1.Enabled = false;
            this.txt银行卡种别1.Enabled = false;
            this.txt银行账号1.Enabled = false;
            this.txt银行账号名2.Enabled = false;
            this.txt银行卡种别2.Enabled = false;
            this.txt银行账号2.Enabled = false;
            this.txt银行账号名3.Enabled = false;
            this.txt银行卡种别3.Enabled = false;
            this.txt银行账号3.Enabled = false;

            this.txt支付方式CD.Enabled = false;
            this.txt备注.Enabled = false;
            #endregion

            //控件的Text不进行清空
            #region
            #endregion
        }
    }

    protected void txt处理区分_TextChange(object sender, EventArgs e)
    {
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");

        //处理区分为空的场合
        if (this.txt处理区分.Text == string.Empty)
        {
            String msg = MessageUtil.GetMessage("GTH000", "IGTH000001");
            lblMsgCD.Text = "IGTH000001";
            lblMsg.Text = msg;
            return;
         }
        //处理区分为1,2,3,9的场合
        else if (this.txt处理区分.Text == "1" || this.txt处理区分.Text == "2" || 
            this.txt处理区分.Text == "3" || this.txt处理区分.Text == "9")
        {
            this.proc清空_Init(this.txt处理区分.Text);
        }
        //处理区分为上述以外的场合
        else
        {
            String msg = MessageUtil.GetMessage("GTH000", "IGTH000002");
            lblMsgCD.Text = "IGTH000002";
            lblMsg.Text = msg;
            return;
        }

    }

    protected void btn清除_Click(object sender, EventArgs e)
    {
        //初期化处理
        #region
        //查询时，各个控件的属性进行控制
        proc清空_Init("0");
        #endregion
    }


}